/*
 * Copyright (C) 2025 Tsingteng MicroSystem
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef _NCI_DATA_H_
#define _NCI_DATA_H_

#include "nci_base.h"
#include "nci_transport.h"
#include "priority_queue.h"

/**
 * @file nci_data.h
 * @brief 定义NCI DATA相关的API
*/

#define NCI_DATA_CHANNEL_MAX_SIZE 10

#define NCI_DATA_DEFAULT_MAX_SIZE 256

#define NCI_DATA_CHANNEL_RF 0
#define NCI_DATA_CHANNEL_HCI 1


/**
 * @brief 初始化 NCI_DATA 模块
 *
 * @return 成功返回NCI_STATUS_OK, 失败返回其他错误码
*/
tNCI_STATUS nci_data_init(const tNCI_INIT_RESP *p_init_resp);
/**
 * @brief 关闭 NCI_DATA 模块
 *
 * @return 成功返回NCI_STATUS_OK, 失败返回其他错误码
*/
tNCI_STATUS nci_data_deinit();
/**
 * @brief 通过conn_id查找通道
 *
 * @note 只能查找已经打开的通道
 *
 * @param conn_id 通道ID
 * @return 查找成功返回通道, 失败返回NULL
*/
tNCI_DATA_CHANNEL *nci_data_find_channel(uint8_t conn_id);

/**
 * @brief 设置NCI DATA通道的初始credit和最大负载数据长度
 *
 * @param conn_id 需要设置的通道ID
 * @param mdpps 最大负载数据长度
 * @param init_credit 初始credit
 * @return 成功返回NCI_STATUS_OK, 失败返回错误码
 */
tNCI_STATUS nci_data_set_channel_info(uint8_t conn_id, uint8_t mdpps, uint8_t init_credit);
/**
 * @brief 打开RF动态通道
 *
 * @param[in] discovery_id RF设备ID
 * @param[in] rf_protocol RF协议
 * @param[out] out_conn_id 返回通道ID
*/
tNCI_STATUS nci_data_open_rf_dynamic_channel(tNCI_RF_DISCOVERY_ID discovery_id, tNCI_RF_PROTOCOL rf_protocol, uint8_t *out_conn_id);
/**
 * @brief 打开NFCEE动态通道
 *
 * @param[in] nfcee_id NFCEE ID
 * @param[in] nfcee_interface NFCEE接口
 * @param[out] out_conn_id 返回通道ID
 *
 * @return 成功返回NCI_STATUS_OK, 失败返回错误码
*/
tNCI_STATUS nci_data_open_nfcee_dynamic_channel(uint8_t nfcee_id, uint8_t nfcee_interface, uint8_t *out_conn_id);
/**
 * @brief 关闭NCI DATA通道
 *
 * @param conn_id 需要关闭的通道ID
 *
 * @return 关闭成功返回NCI_STATUS_OK，失败返回错误码
*/
tNCI_STATUS nci_data_channel_close(uint8_t conn_id);
/**
 * @brief 向指定NCI DATA通道发送数据
 *
 * @param[in] conn_id 通道ID
 * @param[in] cmd 待发送的数据
 * @param[out] rsp 接收数据的容器
 * @param[in] timeout 等待rsp的超时时间
 *
 * @return 发送成功返回NCI_STATUS_OK，失败返回错误码
*/
tNCI_STATUS nci_data_channel_transmit(uint8_t conn_id, tNCI_BUF *cmd, tNCI_BUF *rsp, uint32_t timeout);
/**
 * @brief 通知NCI DATA通道有数据可用
 *
 * @param conn_id 通道ID
 * @param credits 可用数据量
*/
void nci_data_channel_notify_credit(uint8_t conn_id, uint8_t credits);
/**
 * @brief 向指定NCI DATA通道发送数据，异步方式，不等待RSP
 *
 * @param[in] conn_id 通道ID
 * @param[in] data 待发送的数据
 *
 * @return 发送成功返回NCI_STATUS_OK，失败返回错误码
*/
tNCI_STATUS nci_data_channel_transmit_async(uint8_t conn_id, tNCI_BUF *data);
/**
 * @brief 根据conn_id分发NCI DATA通道数据
 *
 * @param conn_id 数据通道ID
 * @param data 接收的数据
 * @param len 数据长度
 */
void nci_data_dispatch(uint8_t conn_id, uint8_t *data, uint16_t len);

#endif  // _NCI_DATA_H_
